//
//  ComplaintViewController.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/9/9.
//

#import "ComplaintViewController.h"

#define feedbackTypeTypeTag 100
#define section2TextViewplaceholder0 @"请填写投诉的具体内容（必填）"
#define section2TextViewplaceholder2 @"请填写投诉的具体内容，游戏紧急问题请联系在线客服（必填）"

@interface ComplaintViewController ()<UITextFieldDelegate, UITextViewDelegate>
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollViewTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomBtnbottom;


@property (weak, nonatomic) IBOutlet UILabel *section1Title;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *section1ViewHeight;
@property (weak, nonatomic) IBOutlet UITextField *section1TextField;
@property (weak, nonatomic) IBOutlet UILabel *section2TextViewplaceholder;
@property (weak, nonatomic) IBOutlet UILabel *section2Number;

@property (nonatomic, assign) NSInteger currentFeedbackType;//当前选择的反馈类型，默认0

@end

@implementation ComplaintViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.centerTitle.text = @"投诉建议";
    self.scrollViewTop.constant = UIDevice.vg_navigationFullHeight;
    self.bottomBtnbottom.constant= UIDevice.vg_safeDistanceBottom + 10;
    self.view.backgroundColor = [UIColor whiteColor];
    
    for (NSInteger i = 0; i < 4; i++) {
        UIView *feedbackTypeView = [self.view viewWithTag:feedbackTypeTypeTag+i];
        VHWeakSelf
        [feedbackTypeView addTapBlock:^(id  _Nonnull obj) {
            VHStrongSelf
            self.currentFeedbackType = feedbackTypeView.tag-feedbackTypeTypeTag;
            self.section2TextViewplaceholder.text = [self textViewplaceholder:self.currentFeedbackType];
            switch (self.currentFeedbackType) {
                case 0:
                    self.section1ViewHeight.constant = 102.5;
                    self.section1Title.text = @"投诉对象";
                    self.section1TextField.placeholder = @"必填，如XX部门-小花";
                    break;
                case 1:
                    self.section1ViewHeight.constant = 0;
                    break;
                case 2:
                    self.section1ViewHeight.constant = 102.5;
                    self.section1Title.text = @"游戏名称";
                    self.section1TextField.placeholder = @"请填写游戏名称（必填）";
                    break;
                case 3:
                    self.section1ViewHeight.constant = 0;
                    break;
                    
                default:
                    break;
            }
        }];
    }
    
    self.currentFeedbackType = 0;
}

- (void)setCurrentFeedbackType:(NSInteger)currentFeedbackType
{
    _currentFeedbackType = currentFeedbackType;
    
    [self setupFeedbackUnselected];
    [self setupFeedbackSelected:currentFeedbackType];
}

- (void)setupFeedbackUnselected
{
    for (NSInteger i = 0; i < 4; i++) {
        UIView *feedbackTypeView = [self.view viewWithTag:feedbackTypeTypeTag+i];
        feedbackTypeView.backgroundColor = kRGBColor(245, 245, 246);
        UILabel *feedbackTypeLabel = (UILabel *)[self.view viewWithTag:feedbackTypeTypeTag+10+i];
        feedbackTypeLabel.textColor = kColor666666;
    }
}
- (void)setupFeedbackSelected:(NSInteger)currentFeedbackType
{
    UIView *feedbackTypeView = [self.view viewWithTag:feedbackTypeTypeTag+currentFeedbackType];
    feedbackTypeView.backgroundColor = kThemeTitleColor;
    UILabel *feedbackTypeLabel = (UILabel *)[self.view viewWithTag:feedbackTypeTypeTag+10+currentFeedbackType];
    feedbackTypeLabel.textColor = [UIColor whiteColor];
}

- (NSString *)textViewplaceholder:(NSInteger)currentFeedbackType
{
    if (currentFeedbackType == 2) {
        return section2TextViewplaceholder2;
    }
    return section2TextViewplaceholder0;
}


- (void)textViewDidChangeSelection:(UITextView *)textView
{
    if (textView.text.length > 0) {
        self.section2TextViewplaceholder.text = @"";
    } else{
        self.section2TextViewplaceholder.text = [self textViewplaceholder:self.currentFeedbackType];
    }
    self.section2Number.text = [NSString stringWithFormat:@"%ld/1000字数", textView.text.length];
}







@end
